<?php
class SideBarArticlesWidget extends CWidget
{
	public $category_id = '';
    public $heading = '';
    public $cssClass = '';
    
    public function run()
    {
		$this->heading = trim($this->heading);
        $criteria = new CDbCriteria();
        $criteria->with = array(
            'localeArticle' => array(
                'condition' => 'locale=:locale',
                'params' => array(':locale' => Yii::app()->language)
            ),
        );
        $criteria->compare('t.status',Article::STATUS_ACTIVE);
        $criteria->order = 't.create_time ASC, t.id ASC';
        if ($this->category_id!='')
        {
            $res = FSM::run('Core.Category.getRootAndChildrenIds',array('id'=>$this->category_id,'status'=>1));
            $catIds = $res->ids;
            $criteria->addInCondition('t.category_id', $catIds);
            // get category title
            $langCat = LanguageCategory::model()->find('locale=:locale AND category_id=:catId',array(':locale'=>Yii::app()->language,':catId'=>$this->category_id));
            if ($this->heading=='' && !is_null($langCat))
                $this->heading = $langCat->title;   
        }
        $models = Article::model()->findAll($criteria);
        $this->render('sideBarArticles',array('models'=>$models));
	}
}
?>

